<template>
	<view class="main" :class="{popupShow:popupShow}">
		<view class="abouttx">
			<view class="about">
				<view class="tabs">
					<view class="tabbox" v-for="(v,k) in title" :key="k" :class="{ tabbox1: k === activeIndex }"
						@click="handleTabClick(k)">
						{{v}}
					</view>
				</view>
				<view class="tixian">
					<view class="txtitle">
						提现金额
					</view>
					<view class="txje">
						<text class="alltxje">全部金额</text><text class="fuhao">¥</text><text
							class="je">{{money?money:0}}</text>
					</view>
				</view>
				<view class="tips">
					<view class="a">
						1 . 提现信息填写：结算信息只需填写一次即可；
						<view class="b">
							备注：结算信息填写后无法直接修改，请您务必仔细填写，如需修改，需通过【我的-联系我们】联系客服修改
						</view>
					</view>
					<view class="a">
						2 .提现额度：10元以上；
					</view>
					<view class="a">
						3 .提现到账时间：3个工作日内；
					</view>
					<view class="a">
						4 .税费提醒
						<u-icon class="jinggao" name="info-circle-fill" color="#999999" size="28"
							@click='tishi'></u-icon>
					</view>
					<view class="a">
						5 .月底三天不支持提现
					</view>
				</view>
			</view>
		</view>
		<view class="aboutyhk">
			<view class="yhk" v-if="activeIndex==0">
				<view class="title">
					到账银行卡信息
				</view>
				<view class="abc">
					<view class="aaa">
						<text class="xing">*</text> 请输入姓名
					</view>
					<input type="text" :class="disabled?'dis':''" v-model.trim="personage.real_name"
						:disabled="disabled">
					<view class="aaa">
						<text class="xing">*</text> 请输入身份证号
					</view>
					<input type="text" :class="disabled?'dis':''" v-model.trim="personage.id_card" :disabled="disabled">

					<view class="aaa">
						<text class="xing">*</text> 请输入开户行
					</view>
					<input type="text" :class="disabled?'dis':''" v-model.trim="personage.bank_name"
						:disabled="disabled">
					<view class="aaa">
						<text class="xing">*</text> 请输入支行（例：x银行x省份x市x区x支行）
					</view>
					<input type="text" :class="disabled?'dis':''" v-model.trim="personage.bank_address"
						:disabled="disabled">
					<view class="aaa">
						<text class="xing">*</text> 请输入银行卡
					</view>
					<input type="text" :class="disabled?'dis':''" v-model.trim="personage.bank_card"
						:disabled="disabled">
					<view class="aaa">
						<text class="xing">*</text> 请输入手机号码
					</view>
					<input type="text" :class="disabled?'dis':''" v-model.trim="personage.mobile" :disabled="disabled">
				</view>
			</view>
			<view class="yhk" v-if="activeIndex==1">
				<view class="title">
					企业结算信息
				</view>
				<view class="abc">
					<view class="aaa">
						<text class="xing">*</text> 公司名称
					</view>
					<input type="text" :class="disabled?'dis':''" v-model.trim="enterprise.company_name"
						:disabled="disabled">
					<view class="aaa">
						<text class="xing">*</text> 统一社会信用代码
					</view>
					<input type="text" :class="disabled?'dis':''" v-model.trim="enterprise.company_code"
						:disabled="disabled">
					<view class="aaa">
						<text class="xing">*</text> 注册地址
					</view>
					<input type="text" :class="disabled?'dis':''" v-model.trim="enterprise.company_address"
						:disabled="disabled">
					<view class="aaa">
						<text class="xing">*</text> 联系电话
					</view>
					<input type="text" :class="disabled?'dis':''" v-model.trim="enterprise.company_telephone"
						:disabled="disabled">
					<view class="aaa">
						<text class="xing">*</text> 银行账号
					</view>
					<input type="text" :class="disabled?'dis':''" v-model.trim="enterprise.bank_card"
						:disabled="disabled">
					<view class="aaa">
						<text class="xing">*</text> 对接人手机号码
					</view>
					<input type="text" :class="disabled?'dis':''" v-model.trim="enterprise.company_user_mobile"
						:disabled="disabled">
				</view>
			</view>
			<view class="btn">
				<view class="tijiao" @click="tijiao">
					提交
				</view>
			</view>
		</view>
		<Gerentx v-if="show1" @showshow='showshow'></Gerentx>
		<Qiyetx v-if="show2" @showshow='showshow'></Qiyetx>
		<MyPopup v-if="TT" :content='content' :tip="tip" @showshow='showtip' @showqx='showtip2'></MyPopup>
	</view>
</template>

<script>
	import {
		Earnings
	} from "@/request/api.js"
	import Gerentx from "@/components/Gerentx.vue"
	import Qiyetx from "@/components/Qiyetx.vue"
	import MyPopup from "@/components/Popup.vue"
	export default {
		data() {
			return {
				TT: false,
				tip: '0',
				title: ['个人提现', '企业提现'],
				activeIndex: 0,
				content: "",
				disabled: false,
				money: 0,
				show1: false,
				show2: false,
				popupShow: false,
				personage: {
					real_name: '',
					id_card: '',
					bank_name: '',
					bank_address: '',
					bank_card: '',
					mobile: '',
					type: 1,
				},
				enterprise: {
					company_name: '',
					company_code: '',
					company_address: '',
					company_telephone: '',
					bank_card: '',
					company_user_mobile: '',
					type: 2,
				},
				type: '',
				timeday: '',
			};
		},
		onLoad(option) {
			let aaa = JSON.parse(decodeURIComponent(option.withdrawalInfo ? option.withdrawalInfo : '[]'))
			this.money = option.money || 0
			if (option.tian == 1) {
				if (aaa.type == 1) {
					this.activeIndex = 0
					this.personage = aaa
					this.disabled = true
				} else if (aaa.type == 2) {
					this.activeIndex = 1
					this.enterprise = aaa
					this.disabled = true
				}
			} else {
				this.disabled = false
			}
			this.time()
		},
		onHide() {
			this.tip = ''
		},
		onUnload() {
			this.tip = ''
		},
		beforeDestroy() {
			this.tip = ''
		},
		methods: {
			time() {
				const today = new Date();
				const totalDays = new Date(today.getFullYear(), today.getMonth() + 1, 0).getDate(); // 获取当月总天数
				const day = today.getDate(); // 获取今天是当月的第几天
				this.timeday = totalDays - day
			},
			handleTabClick(k) {
				if (!this.disabled) {
					this.activeIndex = k
				}
			},
			tijiao() {
				if (this.timeday >= 3) {
					if (this.activeIndex == 0) {
						let isAllFilled = Object.values(this.personage).every(val => val);
						if (isAllFilled) {
							let sfzvalue = this.personage.id_card
							let phone = this.personage.mobile
							let sfzreg =
								/^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/
							// let phonereg = /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/
							let phonereg = /^1[3-9]\d{9}$/
							//  /^1[3-9]\d{9}$/
							if (!sfzreg.test(sfzvalue) && !phonereg.test(phone)) {
								uni.showToast({
									title: '请输入正确的身份证号和手机号码',
									icon: 'none',
									duration: 2000
								})
							} else if (!sfzreg.test(sfzvalue) && phonereg.test(phone)) {
								uni.showToast({
									title: '请输入正确的身份证号',
									icon: 'none',
									duration: 2000
								})

							} else if (sfzreg.test(sfzvalue) && !phonereg.test(phone)) {
								uni.showToast({
									title: '请输入正确的手机号码',
									icon: 'none',
									duration: 2000
								})
							} else if (sfzreg.test(sfzvalue) && phonereg.test(phone)) {
								if (this.disabled) {
									this.Tixian()
									setTimeout(() => {
										this.content = "提现申请已提交"
										this.tip = ''
										this.TT = true
									}, 300)
								} else {
									this.content = '结算信息提交后无法修改，是否确认提交？'
									this.tip = '1'
									this.TT = true
								}

							}
						} else {
							uni.showToast({
								title: "带有*的是必填项",
								duration: 2000,
								icon: "none"
							})
						}

					} else {
						let isAllFilled2 = Object.values(this.enterprise).every(val => val);
						if (isAllFilled2) {
							let entphone = this.enterprise.company_user_mobile
							// let phonereg = /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/
							let phonereg = /^1[3-9]\d{9}$/
							if (!phonereg.test(entphone)) {
								uni.showToast({
									title: '请输入正确的对接人手机号码',
									icon: 'none',
									duration: 2000
								})
							} else {
								if (this.disabled) {
									this.Tixian()
									setTimeout(() => {
										this.content = "提现申请已提交"
										this.tip = ''
										this.TT = true
									}, 300)
								} else {
									this.content = '结算信息提交后无法修改，是否确认提交？'
									this.tip = '1'
									this.TT = true
								}
							}
						} else {
							uni.showToast({
								title: "带有*的是必填项",
								duration: 2000,
								icon: "none"
							})
						}

					}
				} else {
					uni.showToast({
						title: "月底三天不支持提现",
						duration: 2000,
						icon: "none"
					})
				}

			},
			async Tixian() {
				let data = {}
				if (this.activeIndex == 0) {
					let personage = {
						...this.personage
					}
					personage.money = this.money
					data = personage
				} else {
					let enterprise = {
						...this.enterprise
					}
					enterprise.money = this.money
					data = enterprise
				}
				await Earnings.TX(data)
			},
			tishi() {
				if (this.activeIndex == 0) {
					this.show1 = true
				} else {
					this.show2 = true
				}
				this.popupShow = true
			},
			showtip(v) {
				if (this.disabled) {
					this.TT = v
					uni.setStorageSync('abc', 2)
					setTimeout(() => {
						uni.navigateBack({
							delta: 1,
						})
					}, 500)

				} else {
					this.TT = v
					this.Tixian()
					let activeIndex = '2'
					setTimeout(() => {
						uni.redirectTo({
							url: `/pages/Earnings/Earnings?activeIndex=${activeIndex}`
						})
					}, 500)
				}
			},
			showtip2(v) {
				this.TT = v
			},
			showshow(e) {
				if (this.activeIndex == 0) {
					this.show1 = e
				} else {
					this.show2 = e
				}
				this.popupShow = e
			},

		},
		components: {
			Gerentx,
			Qiyetx,
			MyPopup
		}
	}
</script>

<style lang="less" scoped>
	@import url("./Tixian.less");
</style>